/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package plar.Actions;

/**
 *
 * @author spok
 */

import java.awt.Rectangle;
import plar.*;

public class Collision extends Action
{
        public Rectangle platformRectangle;
        public String blockType;
	
        public Collision(Element e)
        {
            
            super("collision",e);
        }
        
     public Collision( Element e,String bt)
     {
            super("collision",e);
            blockType = bt;
     }
     
     public Collision( Element e,String bt,Rectangle pr)
     {
            super("collision",e);
            platformRectangle=new Rectangle(pr);
            blockType = bt;
     }
     
     public Rectangle collisionRectangle()
     {
         Rectangle s=source.getPosition();
         if(platformRectangle!=null)
         {
             if(blockType.equals("platform")||blockType.equals("road"))
                {
                    s = new Rectangle(platformRectangle);
                    s.x+=source.getPosition().x;
                    s.y+=source.getPosition().y;
                }
         }
             
         else s = source.getPosition();
         return s;
     }
    /*@Override*/	
        public boolean doAction(Event e)
	{
         Rectangle s=collisionRectangle();
	 Rectangle t = 
                 ((Collision)
                    ((Element)e.trace.get("target")).getAction("collision"))
                        .collisionRectangle();
         return s.intersects(t);
	}
	
}